home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / c / rtlibrary.readme < prev    next >
Text File  |  1995-02-12  |  6KB  |  137 lines

  1. Short:    A kind of "resource tracking" makes cleanup easier.
  2. Author:   Tomi Ollila <too@cs.hut.fi>
  3. Uploader: too@cs.hut.fi
  4. Type:     dev/c
  5.  
  6. This library is public domain. Use it any way you want. I do :)
  7. No warranty of any kind is given.
  8.  
  9. Rt library provides a way to "remember" what resources has been allocated 
  10. for the task a program is doing. Then, at the end of program execution, one
  11. `delete' -call will go through a stack of allocated stuff and call their
  12. corresponding deallocation functions.
  13.  
  14. The initial and final procedures one must do are quite simple:
  15.  
  16. First, create an rt memory space. Currently this space is statically bound
  17. to the value programmer gives. Programmer must know/quess a value high
  18. enough for all stuff that rt must remember: This is done the following way:
  19.  
  20.     struct RT * rt;
  21.  
  22.     unless (rt = rt_Create(100)) /* #define unless(x) if (!(x)) */
  23.        return 20;
  24.  
  25. This allocates memory for 100 items that rt can remember.
  26.  
  27. ...Now you can for example do the following thing (and then forget the
  28. thing alltogether):
  29.  
  30.     void closeLib(struct Library * base) { CloseLibrary(base); }
  31. ...
  32.  
  33.     unless (DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37))
  34.        return 20;
  35.  
  36.     rt_Add(rt, closeLib, DOSBase);
  37.  
  38. but all this can be done easier by using the provided rt_CloseLib -function:
  39.  
  40.     unless (rt_CloseLib(rt, &DOSBase, "dos.library", 37))
  41.        return 20;
  42.  
  43.  
  44. As you see, the rt -system takes a pointer to deallocation function and a
  45. data pointer to be given as an argument to that function. At the end of
  46. program execution, the following call will do all these deallocation
  47. function calls in reverse order they were installed.
  48.  
  49. rt_Delete(rt);
  50.  
  51.  
  52. The library in current state provides the following functions:
  53.  
  54. /* rt.c */
  55. struct RT * rt_Create(int size); /* creates an rt instance */
  56. struct RTNode * rt_Add(struct RT * rt, void * func, void * data);
  57. struct RTNode * rt_Delete(struct RT * rt);
  58.  
  59. /* rt_remnode.c -- the function below deletes one node */
  60. void rt_RemNode(struct RT * rt, struct RTNode * node);
  61.  
  62. /* rt_remdata.c -- the function below deletes one node searched by data ptr */
  63. void rt_Remdata(struct RT * rt, void * data);
  64.  
  65. /* rt_remsome.c -- function deletes multiple entries ... */
  66. void rt_Remdata(struct RT * rt, void * ptr, ULONG flags);
  67.  
  68. /* rt_exec/rt_openlib.c -- void * as libptr reduces compiler warnings */
  69. struct RTNode * rt_OpenLib(struct RT * rt, void * libptr, 
  70.                 char * name, int version); */
  71.  
  72. /* rt_exec/rt_allocmem.c -- void * as memptr reduces compiler warnings */
  73. struct RTNode * rt_AllocMem(struct RT * rt, void * memptr,
  74.                 ULONG size, ULONG flags);
  75.  
  76. /* rt_dos/rt_open.c */
  77. struct RTNode * rt_Open(struct RT * rt, BPTR * file, char * name, int mode);
  78.  
  79.  
  80. See the test program in test directory of this archive. It demonstrates
  81. the way those rt_Rem* -functions work (1384 bytes long and it uses almost
  82. all the functions provided in the library). 
  83.  
  84. If you want to add your own rt functions to this library, please follow the
  85. convention I've been using in rt_exec/ and rt_dos/ directories. I will gladly
  86. add all your "wrappers" you want to be included in this public distribution
  87. of this library.
  88.  
  89. All sources and this library is compiled w/ gcc only, since it was so easy
  90. to use gcc cross compiler at sun sparcstation while developing this library
  91. (21" monitor, X and Emacs19 rules).
  92.  
  93. Well, This documentation should give you a start of trying and using this
  94. library. Please send me comments about the usability and everything you
  95. could think about this piece of work to the address too@cs.hut.fi.
  96.  
  97. Tomi
  98.  
  99.  
  100. ============================= Archive contents =============================
  101.  
  102. Original  Packed Ratio    Date     Time    Name
  103. -------- ------- ----- --------- --------  -------------
  104.        0       0  0.0% 01-Feb-95 02:40:00  rtlibrary/
  105.        0       0  0.0% 01-Feb-95 02:36:54  rtlibrary/include/
  106.      927     484 47.7% 01-Feb-95 00:14:56  rtlibrary/include/rt.h
  107.      429     276 35.6% 01-Feb-95 02:29:34  rtlibrary/include/rt_dos.h
  108.      539     327 39.3% 01-Feb-95 02:29:28  rtlibrary/include/rt_exec.h
  109.        0       0  0.0% 01-Feb-95 00:42:34  rtlibrary/lib/
  110.     2204     810 63.2% 01-Feb-95 01:46:16  rtlibrary/lib/librt.a
  111.     3541    1577 55.4% 01-Feb-95 02:39:46  rtlibrary/rtlibrary.readme
  112.        0       0  0.0% 01-Feb-95 02:35:54  rtlibrary/src/
  113.     1227     672 45.2% 01-Feb-95 00:41:58  rtlibrary/src/Makefile
  114.        0       0  0.0% 01-Feb-95 01:48:40  rtlibrary/src/rt/
  115.      900     449 50.1% 30-Jan-95 01:40:36  rtlibrary/src/rt/rt.c
  116.      324     235 27.4% 30-Jan-95 01:45:58  rtlibrary/src/rt/rt.o
  117.      647     386 40.3% 30-Jan-95 01:10:04  rtlibrary/src/rt/rt_priv.h
  118.      696     390 43.9% 07-Jan-95 00:33:08  rtlibrary/src/rt/rt_remdata.c
  119.      189     151 20.1% 01-Feb-95 00:42:06  rtlibrary/src/rt/rt_remdata.o
  120.      533     325 39.0% 07-Jan-95 00:33:08  rtlibrary/src/rt/rt_remnode.c
  121.      165     130 21.2% 30-Jan-95 01:36:48  rtlibrary/src/rt/rt_remnode.o
  122.      707     401 43.2% 01-Feb-95 01:40:16  rtlibrary/src/rt/rt_remsome.c
  123.      213     169 20.6% 01-Feb-95 01:40:24  rtlibrary/src/rt/rt_remsome.o
  124.        0       0  0.0% 01-Feb-95 01:48:40  rtlibrary/src/rt_dos/
  125.      574     333 41.9% 30-Jan-95 01:53:22  rtlibrary/src/rt_dos/rt_open.c
  126.      289     187 35.2% 01-Feb-95 00:42:14  rtlibrary/src/rt_dos/rt_open.o
  127.        0       0  0.0% 01-Feb-95 01:48:40  rtlibrary/src/rt_exec/
  128.      572     348 39.1% 01-Feb-95 01:45:34  rtlibrary/src/rt_exec/rt_allocmem.c
  129.      295     191 35.2% 01-Feb-95 01:46:10  rtlibrary/src/rt_exec/rt_allocmem.o
  130.      603     359 40.4% 01-Feb-95 01:45:16  rtlibrary/src/rt_exec/rt_openlib.c
  131.      295     194 34.2% 01-Feb-95 01:46:16  rtlibrary/src/rt_exec/rt_openlib.o
  132.        0       0  0.0% 01-Feb-95 01:46:36  rtlibrary/test/
  133.     1384     888 35.8% 01-Feb-95 01:46:36  rtlibrary/test/test1
  134.     1884     692 63.2% 01-Feb-95 01:47:36  rtlibrary/test/test1.c
  135. -------- ------- ----- --------- --------
  136.    19137    9974 47.8% 01-Feb-95 21:19:30   31 files
  137.